Image Annotation

Create dataset

  • Search "cmd" from windows, run as administrator
    . Pasted image 20250526141315.png

  • Navigate to your Documents folder

cd "%USERPROFILE%\Documents" && cd yolo_projects
  • create a folder, "dataset"
mkdir dataset
cd /dataset/train
notepad covert-jason.py
import json
import os

# Load your Roboflow COCO JSON file
with open("_annotations.coco.json") as f:
    coco = json.load(f)

# Build category lookup
categories = {cat["id"]: cat["name"] for cat in coco["categories"]}

# Build image lookup
images = {img["id"]: img for img in coco["images"]}

# Optional: define your image path prefix for Label Studio to locate the images
IMAGE_PATH_PREFIX = "/data/local-files/?d=train/"

# Collect annotations per image
annotations_by_image = {}
for ann in coco.get("annotations", []):
    img_id = ann["image_id"]
    bbox = ann["bbox"]  # [x, y, width, height]
    category_id = ann["category_id"]

    image = images[img_id]
    width = image["width"]
    height = image["height"]

    # Normalize coordinates for Label Studio
    x = bbox[0] / width * 100
    y = bbox[1] / height * 100
    w = bbox[2] / width * 100
    h = bbox[3] / height * 100

    result = {
        "from_name": "label",
        "to_name": "image",
        "type": "rectanglelabels",
        "value": {
            "x": x,
            "y": y,
            "width": w,
            "height": h,
            "rectanglelabels": [categories[category_id]],
        },
    }

    if img_id not in annotations_by_image:
        annotations_by_image[img_id] = []

    annotations_by_image[img_id].append(result)

# Convert to Label Studio format
label_studio_data = []
for img_id, image in images.items():
    entry = {
        "data": {"image": IMAGE_PATH_PREFIX + image["file_name"]},
        "annotations": [{"result": annotations_by_image.get(img_id, [])}],
    }
    label_studio_data.append(entry)

# Save to file
with open("label_studio_format.json", "w") as f:
    json.dump(label_studio_data, f, indent=2)

print("Conversion complete. Output saved to label_studio_format.json.")
print("Categories:")
for cat_id, cat_name in categories.items():
    print(f"{cat_id}: {cat_name}")


  • run the python file
python covert-jason.py
  • copy the categories from the terminal:
    Pasted image 20250526214745.png

  • Going back the main folder:

cd "%USERPROFILE%\Documents" && cd yolo_projects
  • Activate the environment
cd venv39 && Scripts\activate
  • start the label-studio, (*Need to change to your folder path)
SET DATA_UPLOAD_MAX_NUMBER_FILES=10000
set LOCAL_FILES_SERVING_ENABLED=true
set LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=%USERPROFILE%\\Documents\\yolo_projects\\datasets

or

set LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=C:\\Users\\111872\\Documents\\yolo_projects\\datasets
Label-studio start
  • sign-up a account

Pasted image 20250526152912.png

  • Click "Create Project"
    Pasted image 20250526153223.png

Pasted image 20250526215801.png

Pasted image 20250526215828.pngPasted image 20250526215958.png

  • click the save button.

  • click settings

  • Head to the project settings and select Cloud Storage.

  • Click Add Source Storage and choose Local files from the Storage Type options.

  • Set the Absolute local path  C:\Users\%USERPROFILE%\Documents\yolo_projects\datasets\train.

  • Select Add storage to confirm the setup.

  • Check Image Access: http://localhost:8080/data/local-files/?d=/train/batch_01_frame_5_jpg.rf.4b2f849f8838161c9b480a6979099fad.jpg

  • Go to import

  • find "label_studio_format.json" from "C:\Users%USERPROFILE%\Documents\yolo_projects\datasets\train"

  • Click "import" button

Pasted image 20250526221058.png

Pasted image 20250526221113.png